﻿using System;
using System.Data;
using System.Configuration;
using System.Linq;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Xml.Linq;
using System.Data.SqlClient;
using BTN04.DTO;
using System.Collections.Generic;

namespace BTN04.DAO
{
    public class ChiTietHoaDonDAO
    {
        //ham them chi tiet hoa hoa don
        public int ThemChiTietHoaDon(ChiTietHoaDonDTO  cthdDTO)
        {
            string sql_string ="Insert into ChiTietHoaDon(MaHoaDon,MaSanPham,SoLuongMua,GiaBan,MaNguoiDung) values(";
            sql_string +=cthdDTO.MaHoaDon.ToString ()+","+cthdDTO.MaSanPham.ToString()+","+cthdDTO.SoLuongMua.ToString()+","+cthdDTO.GiaBan.ToString()+ ","+cthdDTO.MaNguoiDung.ToString ()+")";
            SqlConnection connect = new SqlConnection(DataProvider.ConnectionString);
            connect.Open();
            SqlCommand comnd = new SqlCommand(sql_string, connect);
            int kiem = comnd.ExecuteNonQuery();
            connect.Close();
            return kiem;
        }
        //ham lay chi tiet hoa don theo ma nguoi dung
        public DataTable LayChiTietHoaDonTheoMaNguoiDung(int mand)
        {
            SqlConnection cnn = new SqlConnection(DataProvider.ConnectionString);
            string str = "SELECT *";
            str += " FROM ChiTietHoaDon cthd, HoaDon hd ";
            str += " WHERE cthd.MaHoaDon = hd.MaHoaDon AND hd.MaTinhTrangHoaDon=2 And cthd.MaNguoiDung="+mand .ToString ();
            cnn.Open();
            SqlCommand comand = new SqlCommand(str, cnn);
            SqlDataAdapter adapter = new SqlDataAdapter(comand);
            DataTable dt = new DataTable();
            adapter.Fill(dt);
            cnn.Close();
            return dt;
        }


       
    }
}
